package com.ruoyi.courseManagement.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.courseManagement.domain.Courseware;
import com.ruoyi.courseManagement.domain.vo.CoursewareVO;
import com.ruoyi.courseManagement.service.CoursewareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课件管理Controller
 * 
 * @author liao
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/courseManagement/courseware")
public class CoursewareController extends BaseController
{
    @Autowired
    private CoursewareService coursewareService;

    /**
     * 查询课件管理列表
     */
    @PreAuthorize("@ss.hasPermi('courseManagement:courseware:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoursewareVO coursewareVO)
    {
        System.out.println(coursewareVO);
        startPage();
        List<CoursewareVO> list = coursewareService.selectCoursewareList(coursewareVO);
        return getDataTable(list);
    }

    /**
     * 导出课件管理列表
     */
    @PreAuthorize("@ss.hasPermi('courseManagement:courseware:export')")
    @Log(title = "课件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoursewareVO coursewareVO)
    {
        List<CoursewareVO> list = coursewareService.selectCoursewareList(coursewareVO);
        ExcelUtil<CoursewareVO> util = new ExcelUtil<CoursewareVO>(CoursewareVO.class);
        util.exportExcel(response, list, "课件管理数据");
    }

    /**
     * 获取课件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('courseManagement:courseware:query')")
    @GetMapping(value = "/{coursewareId}")
    public AjaxResult getInfo(@PathVariable("coursewareId") Integer coursewareId)
    {
        return success(coursewareService.selectCoursewareByCoursewareId(coursewareId));
    }

    /**
     * 新增课件管理
     */
    @PreAuthorize("@ss.hasPermi('courseManagement:courseware:add')")
    @Log(title = "课件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Courseware courseware)
    {
        return toAjax(coursewareService.insertCourseware(courseware));
    }

    /**
     * 修改课件管理
     */
    @PreAuthorize("@ss.hasPermi('courseManagement:courseware:edit')")
    @Log(title = "课件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Courseware courseware)
    {
        return toAjax(coursewareService.updateCourseware(courseware));
    }

    /**
     * 删除课件管理
     */
    @PreAuthorize("@ss.hasPermi('courseManagement:courseware:remove')")
    @Log(title = "课件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{coursewareIds}")
    public AjaxResult remove(@PathVariable Integer[] coursewareIds)
    {
        return toAjax(coursewareService.deleteCoursewareByCoursewareIds(coursewareIds));
    }
}
